package com.hbx.service.impl;

import com.hbx.constant.OperaResultEnum;
import com.hbx.constant.TableEnum;
import com.hbx.logs.OperaTypeEnum;
import com.hbx.service.SysService;
import com.hbx.utils.Result;
import com.hbx.vo.logs.LogPreSysInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/*
 * @Author:hbx
 * 
 * */
@Service
@Slf4j
public class SysServiceImpl implements SysService {
    @Override
    public void getTableAndOperaInfo(Result r) {
        LogPreSysInfoVo result = new LogPreSysInfoVo();

        // 获得表信息
        TableEnum[] values = TableEnum.values();
        List<LogPreSysInfoVo.TableInfo> tableInfoList = new ArrayList<>();
        for (TableEnum tableEnum : values) {
            LogPreSysInfoVo.TableInfo tableInfo = new LogPreSysInfoVo.TableInfo();
            tableInfo.setTableName(tableEnum.getTableName());
            tableInfo.setTableDesc(tableEnum.getTableDesc());
            tableInfoList.add(tableInfo);
        }
        log.info("【系统模块】:获取表数据完毕,共有{}条数据",tableInfoList.size());
        // 获得操作类型
        OperaTypeEnum[] operaTypeEnums = OperaTypeEnum.values();
        List<LogPreSysInfoVo.OperateType> operateTypeList = new ArrayList<>();
        for (OperaTypeEnum operaTypeEnum : operaTypeEnums) {
            LogPreSysInfoVo.OperateType operateType = new LogPreSysInfoVo.OperateType();
            operateType.setOperateTypeCode(operaTypeEnum.getOperaCode());
            operateType.setOperaType(operaTypeEnum.getOpera());
            operateTypeList.add(operateType);
        }
        log.info("【系统模块】:获取操作类型数据完毕,共有{}条数据",operateTypeList.size());
        // 获得操作结果
        OperaResultEnum[] resultEnums = OperaResultEnum.values();
        List<LogPreSysInfoVo.OperateResult> operateResultList = new ArrayList<>();
        for (OperaResultEnum resultEnum : resultEnums) {
            LogPreSysInfoVo.OperateResult operateResult = new LogPreSysInfoVo.OperateResult();
            operateResult.setOperateResultCode(resultEnum.getResult());
            operateResult.setOperateResult(resultEnum.getDesc());
            operateResultList.add(operateResult);
        }
        log.info("【系统模块】:获取操作结果数据完毕,共有{}条数据",operateResultList.size());
        result.setTableInfoList(tableInfoList);
        result.setOperateTypeList(operateTypeList);
        result.setOperateResultList(operateResultList);

        r.setData(result).setCode(200).setMsg("操作成功");
    }
}
